package ltd.hanamaki.selenium.study.studySelenium;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.server.DriverFactory;
import org.openqa.selenium.remote.service.DriverCommandExecutor;
import org.openqa.selenium.remote.service.DriverService;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author : FHM
 * @data : 2021/9/3 - 10:56
 */
public class Demo08 {



    static WebDriver driver;
    static Navigation navigate;
    static JavascriptExecutor executor;

    @BeforeClass
    public void setUp() {
        /* 3.1.  */
        /* 注册 火狐浏览器打开的位置 */
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        /* 3.2 注册 驱动 */
        driver = new FirefoxDriver();

        /* 实例化 导航对象 */
        navigate = driver.navigate();

    }

    @Test
    public void t() throws InterruptedException {

        driver.get("file:///C:/Users/86130/Desktop/testhtml/workspaceHtml/iframeDemo.html");
////
////        /* 获得 网页上的  元素 来设置 样式  */
        WebElement hanamaki = driver.findElement(By.tagName("h1"));

        executor = ((JavascriptExecutor) driver);
        executor.executeScript("arguments[0].style.color='green'", hanamaki);
        Thread.sleep(3000);
        executor.executeScript("arguments[0].style.color='red'", hanamaki);

        /*  想要 点击 iframe 框架中 的 元素 需要将 光标 切换至 iframe 中 */
        driver.switchTo().frame("w1");

        /* 点击 test1 */
        WebElement test1 = driver.findElement(By.linkText("test1"));
        test1.click();

        /* 想要点击 t1127  就要进入 w2 内联框架中 要先 回到 父窗口 再次进入内联框架*/
        driver.switchTo().parentFrame();
        driver.switchTo().frame("w2");

        driver.findElement(By.linkText("t1127")).click();


    }



}
